function updateProgress() {
    var div = document.getElementById("status");
    div.style.width = (parseInt(div.style.width, 10) + 5) + "%";
    if (div.style.left != "100%") {
        mozRequestAnimationFrame(updateProgress);
    }
}

// mozRequestAnimationFrame(updateProgress);

function draw(timestamp) {
//计算两次重绘的时间间隔
    var diff = timestamp - startTime;
//使用diff 确定下一步的绘制时间
//把startTime 重写为这一次的绘制时间
    startTime = timestamp;
//重绘UI
    mozRequestAnimationFrame(draw);
}

// var startTime = mozAnimationStartTime;
// mozRequestAnimationFrame(draw);

// (function(){
//     function draw(timestamp){
//     //计算两次重绘的时间间隔
//         var drawStart = (timestamp || Date.now()),
//             diff = drawStart - startTime;
//     //使用diff 确定下一步的绘制时间
//     //把startTime 重写为这一次的绘制时间
//         startTime = drawStart;
//         //重绘UI
//         requestAnimationFrame(draw);
//     }
//     var requestAnimationFrame = window.requestAnimationFrame ||
//         window.mozRequestAnimationFrame ||
//         window.webkitRequestAnimationFrame ||
//         window.msRequestAnimationFrame,
//         startTime = window.mozAnimationStartTime || Date.now();
//     requestAnimationFrame(draw);
// })();

function isHiddenSupported() {
    return typeof (document.hidden || document.msHidden ||
        document.webkitHidden) != "undefined";
}

function handleVisibilityChange() {
    var output = document.getElementById("output"),
        msg;
    if (document.hidden || document.msHidden || document.webkitHidden) {
        msg = "Page is now hidden. " + (new Date()) + "<br>";
    } else {
        msg = "Page is now visible. " + (new Date()) + "<br>";
    }
    output.innerHTML += msg;
}

// navigator.geolocation.getCurrentPosition(function (position) {
//     drawMapCenteredAt(position.coords.latitude, positions.coords.longitude);
// }, function (error) {
//     console.log("Error code: " + error.code);
//     console.log("Error message: " + error.message);
// });
navigator.geolocation.getCurrentPosition(function (position) {
    drawMapCenteredAt(position.coords.latitude, positions.coords.longitude);
}, function (error) {
    console.log("Error code: " + error.code);
    console.log("Error message: " + error.message);
}, {
    enableHighAccuracy: true,
    timeout: 5000,
    maximumAge: 25000
});

function fileTest() {
    var filesList = document.getElementById("files-list");
    EventUtil.addHandler(filesList, "change", function (event) {
        var files = EventUtil.getTarget(event).files,
            i = 0,
            len = files.length;
        while (i < len) {
            console.log(files[i].name + " (" + files[i].type + ", " + files[i].size +
                " bytes) ");
            i++;
        }
    });
}

function fileReadTest() {
    var filesList = document.getElementById("files-list");
    EventUtil.addHandler(filesList, "change", function (event) {
        var info = "",
            output = document.getElementById("output"),
            progress = document.getElementById("progress"),
            files = EventUtil.getTarget(event).files,
            type = "default",
            reader = new FileReader();
        if (/image/.test(files[0].type)) {
            reader.readAsDataURL(files[0]);
            type = "image";
        } else {
            reader.readAsText(files[0]);
            type = "text";
        }
        reader.onerror = function () {
            output.innerHTML = "Could not read file, error code is " +
                reader.error.code;
        };
        reader.onprogress = function (event) {
            if (event.lengthComputable) {
                progress.innerHTML = event.loaded + "/" + event.total;
            }
        };
        reader.onload = function () {
            var html = "";
            switch (type) {
                case "image":
                    html = "<img src=\"" + reader.result + "\">";
                    break;
                case "text":
                    html = reader.result;
                    break;
            }
            output.innerHTML = html;
        };
    });
}

function blobSlice(blob, startByte, length) {
    if (blob.slice) {
        return blob.slice(startByte, length);
    } else if (blob.webkitSlice) {
        return blob.webkitSlice(startByte, length);
    } else if (blob.mozSlice) {
        return blob.mozSlice(startByte, length);
    } else {
        return null;
    }
}

function createObjectURL(blob) {
    if (window.URL) {
        return window.URL.createObjectURL(blob);
    } else if (window.webkitURL) {
        return window.webkitURL.createObjectURL(blob);
    } else {
        return null;
    }
}
